package com.rentong.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.rentong.common.core.page.PageDomain;
import com.rentong.common.core.page.TableSupport;
import com.rentong.cust.domain.CustJiesuanVo;
import com.rentong.cust.utils.PageByList;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.rentong.common.annotation.Log;
import com.rentong.common.core.controller.BaseController;
import com.rentong.common.core.domain.AjaxResult;
import com.rentong.common.enums.BusinessType;
import com.rentong.cust.domain.SysRegion;
import com.rentong.cust.service.ISysRegionService;
import com.rentong.common.utils.poi.ExcelUtil;
import com.rentong.common.core.page.TableDataInfo;

/**
 * 区域名称表Controller
 *
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/region/region")
public class SysRegionController extends BaseController {
    @Autowired
    private ISysRegionService sysRegionService;

    /**
     * 查询区域名称表列表
     */
//    //('region:region:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysRegion sysRegion) {
        PageDomain pageDomain = TableSupport.buildPageRequest();
        Integer pageNum = pageDomain.getPageNum();
        Integer pageSize = pageDomain.getPageSize();
        List<SysRegion> list = sysRegionService.selectSysRegionList(sysRegion);
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(PageByList.startPage(list, pageNum, pageSize));
        rspData.setTotal(new PageInfo(list).getTotal());
        return rspData;
    }

    /**
     * 导出区域名称表列表
     */
//    //('region:region:export')")
    @Log(title = "区域名称表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysRegion sysRegion) {
        List<SysRegion> list = sysRegionService.selectSysRegionList(sysRegion);
        ExcelUtil<SysRegion> util = new ExcelUtil<SysRegion>(SysRegion.class);
        util.exportExcel(response, list, "区域名称表数据");
    }

    /**
     * 获取区域名称表详细信息
     */
//    //('region:region:query')")
    @GetMapping(value = "/{regionId}")
    public AjaxResult getInfo(@PathVariable("regionId") Long regionId) {
        return success(sysRegionService.selectSysRegionByRegionId(regionId));
    }

    /**
     * 新增区域名称表
     */
//    //('region:region:add')")
    @Log(title = "区域名称表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysRegion sysRegion) {
        return toAjax(sysRegionService.insertSysRegion(sysRegion));
    }

    /**
     * 修改区域名称表
     */
//    //('region:region:edit')")
    @Log(title = "区域名称表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysRegion sysRegion) {
        return toAjax(sysRegionService.updateSysRegion(sysRegion));
    }

    /**
     * 删除区域名称表
     */
//    //('region:region:remove')")
    @Log(title = "区域名称表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{regionIds}")
    public AjaxResult remove(@PathVariable Long[] regionIds) {
        return toAjax(sysRegionService.deleteSysRegionByRegionIds(regionIds));
    }
}
